
package com.sky.directdeal.activity;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;

import com.sky.directdeal.R;
import com.sky.directdeal.manager.SharedPreferenceManager;

public class SplashActivity extends Activity {
    private static final int SPLASH_DELAY = 1000;
    private static final int NEXT_ACTIVITY = 0;

    @Override
    protected void onCreate( Bundle savedInstanceState ) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);
        startHomeActivity();
    }

    private void startHomeActivity() {
        Message msg = new Message();
        msg.what = NEXT_ACTIVITY;
        splashHandler.sendMessageDelayed(msg, SPLASH_DELAY);
    }
    @SuppressLint("HandlerLeak") 
    private final Handler splashHandler = new Handler() {

        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            try {
                showHomeScreen();
            } catch (Exception ex) {
            }
        }
    };

private void showHomeScreen() {
        
        new Thread(new Runnable() {
            public void run() {}
        }).start();
        boolean isAppLaunched=SharedPreferenceManager.getPreferenceBooleanValue(this, SharedPreferenceManager.Keys.IS_LOC_CONFIGURED);
        if(isAppLaunched){
        	Intent homeActivity = new Intent(this,
                    HomeActivity.class);

            startActivity(homeActivity);
        }else{
        	Intent locationActivity = new Intent(this,
                    UserLocationActivity.class);

            startActivity(locationActivity);
        }
            
        finish();
    }
    
    
    @Override
    public void onBackPressed() {
        super.onBackPressed();
        splashHandler.removeMessages(0);
    }
}
